{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "dfs=pd.read_html('data/List of countries by life expectancy - Wikipedia.htm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "from translate import Translator\n",
    "translator= Translator(to_lang=\"zh\")\n",
    "df=dfs[0]\n",
    "df = df.rename(columns={'Country and regions':'国家/地区', 'Both sexesrank':'两性排名', 'Both sexes lifeexpectancy':'两性预期',\n",
    "       'Female rank':'女性排名', 'Female life expectancy':'女性预期', 'Male rank':'男性排名',\n",
    "       'Male life expectancy':'男性预期', 'Both sexesrank (HALE)':'两性排名(HALE)',\n",
    "       'Both sexes lifeexpectancy (HALE)':'两性预期(HALE)'})\n",
    "countryCN = []\n",
    "for country in df['国家/地区']:\n",
    "    country = translator.translate(country)\n",
    "    print(country)\n",
    "    countryCN.append(country)\n",
    "df['国家/地区'] = countryCN\n",
    "df.to_csv('expectation.csv', index = False)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "pd.options.display.max_rows = None\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
